package com.wbcs.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class UniqueArrayList<E> extends ArrayList<E> implements Cloneable
{
    private static final long serialVersionUID=7739843329266051669L;

    @Override
	public void add(int index,E element)
    {
        if(!super.contains(element)) super.add(index,element);
    }

    @Override
	public boolean add(E element)
    {
        if(!super.contains(element)) return super.add(element);
        return false;
    }

    @Override
	public boolean addAll(Collection<? extends E> collection)
    {
        for(E e:collection)
        {
            add(e);
        }
        return true;
    }

    @Override
	public boolean addAll(int index,Collection<? extends E> collection)
    {
        List<E> cTmp=new ArrayList<E>();
        for(E e:collection)
        {
            if(!super.contains(e))
            {
                cTmp.add(e);
            }
        }
        return super.addAll(index,cTmp);
    }

    @Override
	public UniqueArrayList<E> clone()
    {
        return (UniqueArrayList<E>)super.clone();
    }
}
